<?php
$section = 'user';
$titre = _LB_ACCOUNT_MANAGEMENT;
$smarty->assign("titre", $titre);

//get object ID
$id = Request::getIntNumber('id');
$act = Request::getIntNumber('act');

//get back link
$backlink = Session::getBackLink($section,"list/?");

$user = new Login();
if($id)
{
	if(!$user->get($id))
		redirect($backlink);
}

//if action = UPDATE or CREATE
if ($act == ACT_VALID_EDIT)
{
	$user->FIRST_NAME = trim(Request::get('FIRST_NAME'));
    $user->LAST_NAME = trim(Request::get('LAST_NAME'));
    $user->EMAIL = trim(Request::get('EMAIL'));
    $user->PHONE = trim(Request::get('PHONE'));
    $user->DISABLED = Request::getNumber('DISABLED');
    
	if ($user->validateInput())
	{
		if(!$user->ID){
            $user->PASSWORD = sha1(Request::get("PASS"));
			$user->insert();
        }
		else{
			$user->update();
        }
		redirect($backlink);
	}

}

//create cfer
$cfer = new Cfer(array(
	_LB_ACCUEIL => Utils::getHomeLink(),
	_LB_ACCOUNT_MANAGEMENT => $backlink,
	($id == 0? _LB_ADD_ACCOUNT : _LB_EDIT_ACCOUNT) => Utils::getCurrentLink() ));

//if validate is false, display form again
$smarty->assign('cfer', $cfer);
$smarty->assign('user', $user);
$smarty->assign('backlink', $backlink);
$smarty->display('user_form.html');